![]() |
PATH![]() |
![]() ![]() |
Your application typically uses a
MyControlEditTextValidationProc
function in conjunction with a key filter function to ensure that editable text is valid in cases such as a cut, paste, or clear, where a key filter cannot be called.
Note that if you are using the inline input editable text control variant, the Control Manager will not call your MyControlEditTextValidationProc function during inline input. Instead, you may install your own Text Services Manager TSMTEPostUpdateUPP callback function to validate text during inline input, or your application can validate the input itself, immediately prior to using the text.
Listing 1-2 shows how you can use a MyControlEditTextValidationProc function to ensure that a user-supplied file name does not contain any illegal characters. Note that to enhance readability, no error-checking is included in this sample; a real application would, however, check for errors.
Listing 1-2 Validating a file name with a MyControlEditTextValidationProc function
pascal void MyControlEditTextValidationProc (ControlHandle control)
{
Str31 text;
Size actualSize;
UInt8 i;
// Get the text to be examined from the control.
GetControlData (control, kControlNoPart, kControlEditTextTextTag,
sizeof(Str31) - 1, (Ptr)&text[1], &actualSize);
// Set the string's length byte appropriately for the number of
// characters in the text, limited to the (current) max filename.
if (actualSize <= 31)
text[0] = actualSize;
else
text[0] = 31;
// Replace any colons with dashes.
// Note: This only works with Roman script systems!
for (i = 1; i <= text[0]; i++)
{
if (text[i] == ':')
text[0] = '-';
}
// If this were a real app, there'd be code here to check to see
// whether any text was actually replaced before bothering to redraw.
// Put the replaced text into the control and redraw.
SetControlData(control, kControlNoPart, kControlEditTextTextTag,
text[0], (Ptr)&text[1]);
DrawOneControl(control);
}